﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FileTypeManager.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the FileTypeManager class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine.BusinessLogic
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using Lidocaine.BusinessObjects;

    /// <summary>
    /// Defines the FileTypeManager class.
    /// </summary>
    public static class FileTypeManager
    {
        /// <summary>
        /// Initializes a new instance of the FileType class.
        /// </summary>
        /// <param name="fileTypeId">The identity of the database table's row referencing this filetype.</param>
        public static BusinessObjects.FileType GetFileType(int fileTypeId)
        {
            return Data.FileType.Select(fileTypeId);
        }
        
        /// <summary>
        /// Finds a filetype based on its associated file extension, if it exists.
        /// </summary>
        /// <param name="extension">The extension to search for (e.g. "htm")</param>
        /// <returns>If the extension is found, an FileType is populated and returned. Returns null otherwise.</returns>
        public static BusinessObjects.FileType GetFileTypeByExtension(string extension)
        {
            return Data.FileType.Select(extension);
        }

        /// <summary>
        /// Gets a list of the filetypes associated with this application.
        /// </summary>
        /// <returns>A read only list of HFileType type object.</returns>
        public static List<BusinessObjects.FileType> GetFileTypes()
        {
            return Data.FileType.SelectAll();
        }

        /// <summary>
        /// Inserts the FileType object into the database.
        /// </summary>
        /// <returns>The inserted FileType with a newly populated Id field.</returns>
        public static BusinessObjects.FileType SaveAs(BusinessObjects.FileType fileType)
        {
            return Data.FileType.Insert(fileType);
        }

        /// <summary>
        /// Updates the FileType's database fields.
        /// </summary>
        public static void Save(BusinessObjects.FileType fileType)
        {
            Data.FileType.Update(fileType);
        }

        /// <summary>
        /// Deletes the FileType from the database.
        /// </summary>
        public static void Delete(BusinessObjects.FileType fileType)
        {
            Data.FileType.Delete(fileType);
        }
    }
}